<template>
  <view>
    <wd-tabs v-model="params.status" @change="handleTabsChange">
      <wd-tab title="全部" name=""/>
      <wd-tab title="待付款" name="0"/>
      <wd-tab title="待发货" name="10"/>
      <wd-tab title="待收货" name="20"/>
      <wd-tab title="待评价" name="30"/>
    </wd-tabs>
  </view>

  <view v-if="order && order.total">

  </view>

  <view v-else>
    <wd-gap height="100px"/>
    <wd-status-tip :url-prefix="staticUrl" image="content" tip="暂无内容"/>
  </view>


</template>

<script setup lang="ts">

import {ref} from "vue";
import {onLoad, onReachBottom} from "@dcloudio/uni-app";
import type {Order, OrderPageParam} from "@/api/order/model";
import {getOrderPageList} from "@/api/order";

const staticUrl = import.meta.env.VITE_STATIC_URL + '/tip/'
const order = ref<PageResult<Order>>()
const params = ref<OrderPageParam>({
  pageNo: 1,
  pageSize: 10,
  status: '',
})

onLoad(async () => {
  order.value = (await getOrderPageList(params.value)).data
})

/**
 * 切换 Tab
 */
const handleTabsChange = async e => {
  params.value.status = e.name
  order.value = (await getOrderPageList(params.value)).data
}

/**
 * 触底加载更多
 */
onReachBottom(async () => {
  let totalCount = params.value.pageNo! * params.value.pageSize!
  if (totalCount >= order.value?.total!) return
  let {data: {list}} = await getOrderPageList(params.value)
  order.value?.list.concat(list)
})


</script>


<style scoped lang="scss">

</style>
